package com.ls.cloud.business.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

/**
 * @author: candy33
 * @Date: 2022/05/11 23:46
 * com.example.business.entity
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public class BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "GeneratedUUID")
    @GenericGenerator(name = "GeneratedUUID", strategy = "com.ls.cloud.business.common.GeneratedUUID")
    protected String id;

    @Column(name = "deleted", nullable = false, columnDefinition = "tinyint(1) default 0 comment '是否删除，默认0未删除'")
    protected boolean deleted;

    @Column(name = "create_by_id", updatable = false, columnDefinition = "int(11) comment '创建人ID'")
    protected Integer createById;

    @Column(name = "create_by_real_name", updatable = false, columnDefinition = "varchar(30) default '' comment '创建人名称'")
    protected String createByRealName;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_by_date", updatable = false, columnDefinition = "datetime comment '创建时间'")
    protected Date createByDate;

    @Column(name = "update_by_id", insertable = false, columnDefinition = "int(11) comment '修改人ID'")
    protected Integer updateById;

    @Column(name = "update_by_real_name", insertable = false, columnDefinition = "varchar(30) default '' comment '修改人名称'")
    protected String updateByRealName;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "update_by_date", insertable = false, columnDefinition = "datetime comment '修改时间'")
    protected Date updateByDate;

    /**
     * 租户ID
     */
    @Column(name = "tenant_id", updatable = false, columnDefinition = "int(11) comment '租户ID'")
    protected String tenantId;
}
